# Process this file with autoconf to produce a configure script.
AC_PREREQ([2.63])

AC_INIT([catchthealien], [0.1.31], [Christian.Andreas.Mueller@googlemail.com])
AC_CONFIG_SRCDIR([src/main.cpp])
AC_CONFIG_HEADERS([config.h])
AM_INIT_AUTOMAKE

# Checks for programs.
AC_PROG_CXX
#AC_PROG_LIBTOOL
AC_PROG_MAKE_SET
AC_PROG_INSTALL

AC_LANG_CPLUSPLUS

#Checks for Libs
AC_CHECK_LIB([crystalspace-1.2], [main], [], [echo "ERROR: crystalspace-1.2 library not found." && exit 1])
#AC_CHECK_HEADER([cssysdef.h], [], [use_crystal=no])
AC_CHECK_LIB([xerces-c], [_init], [], [use_xml=no])
AC_CHECK_HEADER([xercesc/framework/MemBufInputSource.hpp], [], [use_xml=no])
AC_CHECK_HEADER(windows.h, [SYS=windows], [SYS=other])
AC_SUBST(SYS)
if test "$SYS" = "windows"; then
	AC_CHECK_LIB([zlib], [gzread], [], [AC_MSG_ERROR([zlib library not found])])
else
	AC_CHECK_LIB([pthread], [pthread_create], [], [echo "ERROR: pthread library not found." && exit 1])
	AC_CHECK_LIB([dl], [dlopen], [], [AC_MSG_ERROR([dl library not found])])
	AC_CHECK_LIB([z], [main], [], [AC_MSG_ERROR([z library not found])])
fi

##check for crystal space
CS_CONFIG="cs-config"
AC_ARG_WITH(crystal,
	[	--with-crystal=DIR	CrystalSpace source tree ],
	[
		if test $withval != yes; then
			CS_CONFIG=${withval}/cs-config
		fi
])

CS_CXXFLAGS=`$CS_CONFIG --cxxflags`
CS_LIBDIR=`$CS_CONFIG --libdir`

CXXFLAGS="${CXXFLAGS} ${CS_CXXFLAGS}"
LDFLAGS="${LDFLAGS} -L${CS_LIBDIR}"


## end check for crystal space

AC_SUBST(CS_CXXFLAGS)
AC_SUBST(CS_LIBS)
AC_CHECK_HEADER([cssysdef.h], [],[AC_MSG_ERROR([Couldn't find CrystalSpace headers.])])
#AC_DEFINE(__CRYSTAL_SPACE__, [] , [])


# Checks for header files.
AC_HEADER_STDC
AC_HEADER_STDBOOL

# Checks for typedefs, structures, and compiler characteristics.
AC_C_CONST
AC_TYPE_SIZE_T
AC_HEADER_TIME

AC_CONFIG_FILES([Makefile src/Makefile])

AC_OUTPUT
